package com.team622.shop.goods.service.service.impl;

import com.team622.shop.goods.model.entity.Brand;
import com.team622.shop.goods.service.mapper.BrandMapper;
import com.team622.shop.goods.service.service.BrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author team622
 * @since 2025-07-16
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Override
    public Page<Brand> pageQuery(Integer current, Integer pageSize, String name, Integer isShow) {
        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();

        // 添加品牌名称模糊查询条件
        queryWrapper.like(StringUtils.hasText(name), Brand::getName, name);
        // 添加状态查询条件
        queryWrapper.eq(isShow != null, Brand::getIsShow, isShow.byteValue());
        // 按排序字段降序排列
        queryWrapper.orderByDesc(Brand::getSort);

        // 执行分页查询
        return this.page(new Page<>(current, pageSize), queryWrapper);
    }
}
